<?
	$results = array();
	require_once('../fun/accounts.php');
	if(isset($_REQUEST['returnUrl']))
		$_SESSION['returnUrl'] = $_REQUEST['returnUrl'];
	if(!isset($_SESSION['returnUrl']) && isset($_SERVER['HTTP_REFERER']))
		$_SESSION['returnUrl'] = $_SERVER['HTTP_REFERER'];
	
	if(isset($_POST['email'])) {
		$row = $_POST;
		$results = PerfromLogin($_POST['email'], $_POST['password']);
		if($results === true) {
			$returlUrl = !empty($_SESSION['returnUrl']) ? $_SESSION['returnUrl']: '../home/';
			header('Location: $returnUrl');
			die();
		}else{
			$row = array('email'=>NULL, 'password'=>NULL);
		}
	}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login to &psi; Database</title>
<? include ("../inc/required-links.php") ?>
</head>

<body>
<div id="wrapper">
	<div id="l_l"></div> 
    <div id="left">
		<?php include ('../nav/nav.php') ?>
    </div>
    <div id="main">
		<?php include ('../inc/header.php') ?>
        <div id="t_bg"></div>
        <div id="content">
			<div class="otstup">
            	<div id="main_left">
                	<div class="corners" style="width:auto; margin:auto;">
                    	<div class="text">
                            <form id="login" style="" action="login.php">
                                <label for="email"><strong>Email:</strong></label>
                                <input type="email" id="email" name="email" value="" maxlength="150" />
                                <br />
                                <label for="password"><strong>Password:</strong></label>
                                <input type="password" id="password" name="password" value="" maxlength="50" />
                                <br />
                                <input class="btn btn-mini" type="submit" value="Login" />
                            </form><br /> 
                            <p style="margin-top:5px;">
                                <a href="#">Forgot Password</a> | <a href="#">New User</a><br />
                                <a href="/~N02425083/fall12/psych_db/user/index.php">View Users</a>
                            </p><br />
                        </div>
                    </div>
                </div>
                <div id="right">
					<?php include ('../inc/cat_box1.php') ?>
					<?php include ('../inc/cat_box3.php') ?>
					<?php include ('../inc/cat_box4.php') ?>
					<?php include ('../inc/sn_links.php') ?>
                </div>
        		<div class="clear"></div>
        	</div>
        </div>
        <div class="clear"></div>  
        <div id="foot">
        	<?php include ('../inc/footer.php') ?>
		</div>
		<?php include ('../inc/copywright.php') ?>
        </div>
<div class="clear"></div> 
</div>
</body>
</html>
